package com.gxuwz.handler;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import com.gxuwz.entity.SysUser;
import com.gxuwz.service.IUserInfoService;

/**
 * 配置登陆成功处理器
 * @author h
 *
 */
public class MyLoginSuccessHandler implements AuthenticationSuccessHandler {

	@Resource(name = "userInfoService")
	private IUserInfoService userInfoService;

	@Override
	public void onAuthenticationSuccess(HttpServletRequest req,
			HttpServletResponse resp, Authentication authentication)
			throws IOException, ServletException {
		SysUser user = null;
		Object o = SecurityContextHolder.getContext().getAuthentication()
				.getPrincipal();
		if (o != null && o instanceof SysUser) {
			user = (SysUser) o;
			resp.sendRedirect("User_doLogin.action");
			System.out.println("密码:" + user.getPassword());
			HttpSession session = req.getSession();
			if (session != null) {
				session.setAttribute("user", user);
			}
		}
	}

}
